package com.newviews.tcmip.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.newviews.tcmip.common.constant.CommonConsts;
import com.newviews.tcmip.common.model.ResultModel;
import com.newviews.tcmip.pojo.po.EtcmPxTypePo;
import com.newviews.tcmip.pojo.vo.prescription.EtcmPxTypeRespVO;
import com.newviews.tcmip.pojo.vo.ui.EtcmUiElRespVO;
import com.newviews.tcmip.service.inf.EtcmPxTypeServiceInf;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 字典-处方分类 前端控制器
 * </p>
 *
 * @author lxc
 * @since 2024-02-29
 */
@RestController
@RequestMapping("/etcm/prescription/type")
@Api(tags = "处方类型信息")
public class EtcmPxTypeController {
    @Autowired
    private EtcmPxTypeServiceInf etcmPxTypeService;

    @GetMapping("/list")
    @ApiOperation("处方类型数据")
    public ResultModel<List<EtcmPxTypeRespVO>> getList(@RequestParam String langCode){
        List<EtcmPxTypePo> list = etcmPxTypeService.list(new QueryWrapper<EtcmPxTypePo>().eq(EtcmPxTypePo.LANGUAGE_CODE, langCode).eq(EtcmPxTypePo.STATUS, CommonConsts.COMMON_YES).orderByAsc(EtcmPxTypePo.TYPE_SORT));
        List<EtcmPxTypeRespVO> collect = list.stream().map(workOrderVo -> {
            EtcmPxTypeRespVO exportVo = new EtcmPxTypeRespVO();
            BeanUtils.copyProperties(workOrderVo, exportVo);
            return exportVo;
        }).collect(Collectors.toList());
        return new ResultModel<List<EtcmPxTypeRespVO>>().success(collect);
    }
}
